cmake_minimum_required(VERSION 3.6)  
project(lfs)


find_package(luajit REQUIRED CONFIG)

# 获取当前目录下要编译的源文件  
file(GLOB_RECURSE SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/src/*.c)

#允许编译时不连接
# string(REPLACE " -Wl,--no-undefined" "" CMAKE_MODULE_LINKER_FLAGS ${CMAKE_MODULE_LINKER_FLAGS})
# string(REPLACE " -Wl,--no-undefined" "" CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS})

# 添加要编译的源文件  

if(BUILD_SHARED_LIBS)
    add_library(lfs MODULE ${SRC_FILES})
    set_target_properties(lfs PROPERTIES PREFIX "")
else()
	add_library(lfs STATIC ${SRC_FILES})
endif()

# 添加头文件搜索路径
target_include_directories(lfs PUBLIC 
    ${CMAKE_CURRENT_LIST_DIR}/src
    ${luajit_INCLUDE_DIRS}
)
target_link_libraries(lfs PUBLIC 
    ${luajit_LIBRARIES}
)

# 获取当前目录下的所有 .h 文件  
file(GLOB_RECURSE HEAD_FILES ${CMAKE_CURRENT_LIST_DIR}/src/*.h)

# 安装库文件  
install(TARGETS lfs DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)  
install(FILES ${HEAD_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/include)